import { useState, useEffect } from 'react'

export const useKeyPress = (domNode = document.body) => {
	const [key, setKey] = useState<any>(null)
	useEffect(() => {
		const handleKeyPress = (evt: KeyboardEvent) => {
			setKey(evt.keyCode)
		}
		domNode.addEventListener('keypress', handleKeyPress)
		return () => {
			domNode.removeEventListener('keypress', handleKeyPress)
		}
	}, [domNode])
	return key
}